package com.czx.config;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

@Configuration
public class CaptchaConfig {
    //生成验证码
    @Bean
    public Producer captchaProducer() {
        Properties properties = new Properties();
        // 配置验证码生成器的相关属性，如宽度、高度、字符长度等
        properties.setProperty("kaptcha.image.width", "200");
        properties.setProperty("kaptcha.image.height", "50");
        properties.setProperty("kaptcha.textproducer.char.length", "4");
        // 更多配置可根据需求进行设置
        DefaultKaptcha captchaProducer = new DefaultKaptcha();
        captchaProducer.setConfig(new Config(properties));
        return captchaProducer;
    }
}